//
//  RetweetCellView.swift
//  微博
//
//  Created by mac on 15/12/20.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit
import SnapKit

class RetweetCellView: UIView {
    
    private var retweetPictureBottom : Constraint?
    var retweeted:Status? {
        didSet{
            retweetLabel.text = "@" + (retweeted?.user?.name ?? "") + (retweeted?.text ?? "")
            retweetPicture.urls = retweeted?.picURLs
            //卸载约束
            self.retweetPictureBottom?.uninstall()
            if let urls = retweeted?.picURLs where urls.count > 0 {
                self.snp_updateConstraints { (make) -> Void in
                    //需要设置属性
                    self.retweetPictureBottom = make.bottom.equalTo(retweetPicture.snp_bottom).offset(StatusCellMarigin).constraint
                }
            }else {
                self.snp_updateConstraints { (make) -> Void in
                    //需要设置属性
                    self.retweetPictureBottom = make.bottom.equalTo(retweetLabel.snp_bottom).offset(StatusCellMarigin).constraint
                }

            }
            
        }
    }
    
    //重写构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置ui
    private func setupUI() {
        addSubview(retweetLabel)
        addSubview(retweetPicture)
        
        //设置约束
        retweetLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self).offset(StatusCellMarigin)
        }
        retweetPicture.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetLabel.snp_bottom).offset(StatusCellMarigin)
            make.left.equalTo(retweetLabel.snp_left)
        }
        self.snp_makeConstraints { (make) -> Void in
            //需要设置属性
           self.retweetPictureBottom = make.bottom.equalTo(retweetPicture.snp_bottom).offset(StatusCellMarigin).constraint
        }
    }
    //懒加载
    private lazy var retweetLabel:UILabel = UILabel(content: "我是转发微博", color: UIColor.lightGrayColor(), fontSize: 16, marigin: StatusCellMarigin)
    private lazy var retweetPicture:PictureCellView = PictureCellView()

}
